package swimv2.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Swimv2.UtenteRegistrato;

/**
 * Servlet implementation class RilasciaFeedback
 */
public class RilasciaFeedback extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RilasciaFeedback() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Controlla che l'utente sia loggato altrimenti lo reindirizza alla index del sito.
				HttpSession session = request.getSession();
				UtenteRegistrato user = (UtenteRegistrato) session.getAttribute("utente");
				if (user==null){
					response.sendRedirect("Index.jsp");
					return;
				}else if(user.getTipo().equals("amministratore")){
					response.sendRedirect("Notifiche");
					return;
				}
				Integer id =  Integer.parseInt(request.getParameter("id"));
				if (id!=null){
					session.setAttribute("id",id);
					response.sendRedirect("Feedback.jsp");
				}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.sendRedirect("Notifiche");
	}

}
